<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <!-- 引入vue和axios -->
    <script src="js/plugins/vue/dist/vue.js"></script>
    <script src="js/plugins/axios/dist/axios.js"></script>
    <!-- axios全局配置 -->
    <script src="js/common.js"></script>
</head>
<body>
<div id="myApp"></div>
<script type="text/javascript">
    new Vue({
        el:"#myApp",
        mounted(){
            //获取地址栏的地址
            let path = location.href;//http://bugtracker.itsource.cn/callback.html?code=061csXkl2prim84qysml24JwCR3csXks&state=1
            //将地址栏的数据转成json对象
            let code = parseUrlParams2Obj(path).code;
            //微信登陆
            //将code传递到后端 去获取access_token
            this.$http.post("/login/wechat",{"code":code}).then(res=>{
                if(res.data.success){//绑定了用户 - 免密登陆
                    //获取响应信息 - 使用解构表达式的方式获取
                    let {loginInfo,token} = res.data.resultObj;
                    localStorage.setItem("token",token);
                    //JSON.stringify 将json对象转成json格式的字符串
                    localStorage.setItem("loginInfo",JSON.stringify(loginInfo));
                    //配置登陆之后访问的地址
                    location.href="index.html";

                }else{//没有绑定用户 - 跳转到绑定页面
                    //access_token: "52_ULb4rdXaFd2HuokxETYE0aU8N7lZbOIDfFYi67xlPuJYRHDofiyXQMLOm8NuL9vKiZr2UxaVFMMP5p8ek_u6BifGqox_BEL_fN1tr3eGhcU"
                    //openid: "oa9wA05yEYJLG9riOreQ0zWlXee4"
                    let access_token = res.data.resultObj.access_token;
                    let openid = res.data.resultObj.openid;
                    location.href="binder.html?access_token="+access_token+"&openid="+openid;
                }
            }).catch(res=>{
                alert("系统错误！");
            })
        }
    })


</script>
</body>
</html>